//  Created by Phan Ba Minh on 4/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "FBFunLoginDialog.h"
#import <Foundation/Foundation.h>
#import "APIRequester.h"
#import "FBDialog.h"

//#define STRING_FB_APP_ID                                    @"342694312412758" // Free
//#define STRING_FB_APP_ID                                    @"210849718975311" // Hackbook
#define STRING_FB_APP_ID                                    @"382972025131546"

#define ARRAY_FB_APP_PERMISSION                             [[NSArray alloc] initWithObjects:@"publish_stream", @"read_stream", @"friends_likes", @"user_questions", @"friends_questions", nil]
//#define STRING_FB_APP_PERMISSION                            @"read_stream,publish_stream,friends_likes,user_photos,friends_photos"
//#define STRING_FB_APP_PERMISSION                            @"read_stream,publish_stream,user_photos,email,user_birthday"
#define STRING_FB_APP_PERMISSION                      @"read_stream,publish_stream,user_photos,email,user_birthday,friends_likes,user_questions,friends_questions"

#define STRING_FB_MESSAGE_CONNECTION_ERROR                  @"Network Error. Please check the reception and the connection settings."
#define STRING_CODER_FB_USER_ID								@"STRING_CODER_FB_USER_ID"
#define STRING_CODER_FB_NAME								@"STRING_CODER_FB_NAME"
#define STRING_CODER_FB_PICTURE								@"STRING_CODER_FB_PICTURE"
#define STRING_CODER_FB_ACCESS_TOKEN						@"STRING_CODER_FB_ACCESS_TOKEN"
#define	STRING_CODER_FB_LOGIN_STATUS						@"STRING_CODER_FB_LOGIN_STATUS"
#define STRING_CODER_FB_FIRST_NAME							@"STRING_CODER_FB_FIRST_NAME"
#define STRING_CODER_FB_LAST_NAME							@"STRING_CODER_FB_LAST_NAME"
#define	STRING_CODER_FB_EMAIL								@"STRING_CODER_FB_EMAIL"
#define	STRING_CODER_FB_GENDER								@"STRING_CODER_FB_GENDER"
#define	STRING_CODER_FB_ABOUT								@"STRING_CODER_FB_ABOUT"

#define STRING_REQUEST_FB_USER_GET_DATA(a)                                          [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@&fields=name,id,picture", a]
#define STRING_REQUEST_FB_SEARCH_RAPID(long, lat, dis, limit)                       [NSString stringWithFormat:@"https://graph.facebook.com/search?type=place&center=%f,%f&distance=%i&access_token=%@&limit=%i", long, lat, dis, USER_DEFAULT_FB_ACCESSTOKEN, limit]
#define STRING_REQUEST_FB_SEARCH_FULL(name, long, lat, dis, limit)                  [NSString stringWithFormat:@"https://graph.facebook.com/search?q=%@&type=place&center=%f,%f&distance=%i&access_token=%@&limit=%i", name, long, lat, dis, USER_DEFAULT_FB_ACCESSTOKEN, limit]
#define STRING_REQUEST_FB_CHECKINS(id, long, lat)                                   [NSString stringWithFormat:@"https://graph.facebook.com/me/checkins?sdk_version=2&place=%@&message=&format=json&coordinates={\"longitude\":%@,\"latitude\":%@}&sdk=ios&access_token=%@", id, long, lat, USER_DEFAULT_FB_ACCESSTOKEN]
#define STRING_REQUEST_FB_PICTURE_URL(id)                                           [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", id]
//#define STRING_REQUEST_FB_PLACE_MAP(name, id)                           [NSString stringWithFormat:@"http://www.facebook.com/pages/%@/%@", name, id]
#define STRING_REQUEST_FB_PLACE_MAP(id)                                             [NSString stringWithFormat:@"http://www.facebook.com/%@", id]
#define STRING_REQUEST_FB_ADD_PLACE(name, lat, long, accuracy, timestamp)           [NSString stringWithFormat:@"https://m.facebook.com/places/search.php?q=%@&json_location={""latitude"":%f,""longitude"":%f,""accuracy"":%@,""timestamp"":%@}", name, lat, long, accuracy, timestamp]

#define STRING_REQUEST_TW_SEARCH_RADIUS(hash,lat, long, radius ,count ,page)        [NSString stringWithFormat:@"http://search.twitter.com/search.json?q=%@&geocode=%f,%f,%fkm&rpp=%d&page=%d",hash, lat,long,radius,count,page]
//#define STRING_REQUEST_FB_SEARCH_SCREEN(str)                    [NSString stringWithFormat:@"http://touch.facebook.com/places/search.php?__user=%@",str]
#define STRING_REQUEST_FB_SEARCH_SCREEN(str)                                    [NSString stringWithFormat:@"http://m.facebook.com/places/search.php?__user=%@",str]

#define STRING_REQUEST_FB_PLACE_GET_INFO(id)                                    [NSString stringWithFormat:@"https://graph.facebook.com/%@", id]
#define STRING_REQUEST_FB_POST_TO_WALL_ME_PUBLIC(message, access_token)         [NSString stringWithFormat:@"https://api.facebook.com/method/stream.publish?message=%@&access_token=%@", message, access_token]
#define STRING_REQUEST_FB_POST_TO_WALL_HAS_IMAGE(message, user_id, attachment, access_token)            [NSString stringWithFormat:@"https://api.facebook.com/method/stream.publish?message=%@&target_id=%@&uid=%@&attachment=%@&access_token=%@", message, user_id, user_id, attachment, access_token]
#define STRING_REQUEST_FB_POST_TO_WALL_HAS_PLACE(facebook_id, message, access_token, place)             [NSString stringWithFormat:@"https://graph.facebook.com/%@/feed?message=%@&access_token=%@&place=%@", facebook_id, message, access_token, place]

// FACEBOOK REQUEST
#define STRING_REQUEST_NAME                                             @"name" 
#define STRING_REQUEST_SRC                                              @"src"
#define STRING_REQUEST_HREF                                             @"href"
#define STRING_REQUEST_DESCRIPTION                                      @"description"
#define STRING_REQUEST_MEDIA                                            @"media"
#define STRING_REQUEST_CAPTION                                          @"caption"
#define STRING_REQUEST_HREF                                             @"href"

typedef enum
{
    ENUM_FB_FUN_LOGIN_MANAGER_STEP_INVALID,
    ENUM_FB_FUN_LOGIN_MANAGER_STEP_START,
    ENUM_FB_FUN_LOGIN_MANAGER_STEP_DISPLAY_REQUIRED,
    ENUM_FB_FUN_LOGIN_MANAGER_STEP_DISPLAYED,
    ENUM_FB_FUN_LOGIN_MANAGER_STEP_LOGIN_FAIL,
    ENUM_FB_FUN_LOGIN_MANAGER_STEP_LOGIN_FINISH,
    ENUM_FB_FUN_LOGIN_MANAGER_STEP_LOGIN_CANCEL
}ENUM_FB_FUN_LOGIN_MANAGER_STEP;

@protocol FBFunLoginManagerDelegate <NSObject>
@required
- (void)changeBackFromFBFunLoginManager;
@end

@interface FBFunLoginManager : NSObject <FBFunLoginDialogDelegate, UIAlertViewDelegate, FBDialogDelegate> {
    ENUM_FB_FUN_LOGIN_MANAGER_STEP      _stepFBFunLoginManager;
    UIAlertView                         *_alertViewFBLoginFail;
	APIRequester						*_APIRequester;
}
@property (nonatomic, retain) NSString *userID;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *fName;
@property (nonatomic, retain) NSString *lName;
@property (nonatomic, retain) NSString *pictureURL;
@property (nonatomic, retain) NSString *email;
@property (nonatomic, retain) NSString *accessToken;
@property (nonatomic, retain) NSString *gender;
@property (nonatomic, retain) NSString *about;
@property (nonatomic, strong) NSDate   *birthday;
@property (nonatomic, strong) NSDate   *updateTime;
@property (nonatomic, assign) id<FBFunLoginManagerDelegate> delegate;
@property (nonatomic, retain) FBFunLoginDialog *FBLoginDialogVC;

@property (nonatomic) BOOL loginStatus;

- (void)logout;
- (void)login;
- (void)reLogin;
- (void)update;
- (void)save;

- (UIViewController *)getFBControllerWithDelegate:(id)idDelegate;
+ (FBFunLoginManager *)Shared;
@end
